package dao;

import entity.Vegetable;
import util.DBMannager;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class VegetablequeryDao {
    public List<Vegetable> querybyName(String vegetablename) throws SQLException {

        List<Vegetable> vegetableList = new ArrayList<Vegetable>();
        Connection connection = DBMannager.getConnection();
        String sql = "select * from vegetable where vegename = ?";

        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            ps = connection.prepareStatement(sql);
            ps.setString(1,vegetablename);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        try {
            rs=ps.executeQuery();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        while (rs.next()){
            Vegetable vegetable = new Vegetable();
            vegetable.setVegename(vegetablename);
            vegetable.setPlanttime(rs.getDate("planttime"));
            vegetable.setNumber(rs.getInt("number"));
            vegetable.setVstatus(rs.getInt("vstatus"));
            vegetable.setPrice(rs.getBigDecimal("price"));
            vegetableList.add(vegetable);
        }
        return vegetableList;

    }
}
